from woniusales_ui_test5_ddt.page.basepage import BasePage
from selenium.webdriver.common.by import By


class LoginPage(BasePage):
    """继承基础页面的所有功能"""
    woniusales_url = "http://localhost:8080/woniusales/"
    implicitly_wait = 10
    username_locator = (By.ID, "username")
    password_locator = (By.ID, "password")
    verifycode_locator = (By.ID, "verifycode")
    login_buttion_locator = (By.XPATH, '//button[@onclick="doLogin(\'null\')"]')
    alert_meg_locator = (By.CSS_SELECTOR, '.bootbox-body')

    def __init__(self):
        super(LoginPage, self).__init__()
        self.dr.implicitly_wait(self.implicitly_wait)
        self.dr.maximize_window()
        self.dr.get(self.woniusales_url)

    def input_username(self, username):
        """提供输入用户名的功能: 定位 和 输入的内容"""
        self.input_text(self.username_locator, username)

    def input_password(self, password):
        self.input_text(self.password_locator, password)

    def input_verifycode(self, verifycode):
        self.input_text(self.verifycode_locator, verifycode)

    def click_login(self):
        self.click(self.login_buttion_locator)

    def get_alert_meg(self):
        return self.get_text(self.alert_meg_locator)

    def admin_login_fast(self):
        self.input_username("admin")
        self.input_password("admin123")
        self.input_verifycode("0000")
        self.click_login()
